package com.yourwork.dao.imp;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.yourwork.basedao.imp.BaseDaoImp;
import com.yourwork.common.jpa.ClienteleRepositoey;
import com.yourwork.dao.ClienteleDao;
import com.yourwork.model.Clientele;
@Repository(value="clienteleDao")
public class ClienteleDaoImp extends BaseDaoImp implements ClienteleDao {
	@Autowired
	private ClienteleRepositoey customerRepositoey;
	//分页查询
	public Page<Clientele> queryCustomer(Pageable pageable) {
		// TODO Auto-generated method stub
		return customerRepositoey.findAll(pageable);
	}
	//条件查询
	@Transactional
	public Clientele quserCUserName(String userName) {
		// TODO Auto-generated method stub
		String phone = userName;
//		String hql = "FROM Clientele c WHERE c.phone = '0001' OR c.userName = '0001'";
//		List list = new ArrayList();
//		System.out.println(this.queryUniqueByHql(hql, list));
		return customerRepositoey.findByUserNameOrPhone(userName, phone);
	}
	//修改用户记录
	public void updateCustomer(Clientele customer) {
		// TODO Auto-generated method stub
		customerRepositoey.saveAndFlush(customer);
	}
	//新增用户
	public void insertCustomer(Clientele customer) {
		// TODO Auto-generated method stub
		customerRepositoey.save(customer);
	}
	public int countCustomer() {
		// TODO Auto-generated method stub
		return (int) customerRepositoey.count();
	}

}
